// service/txIntendant/txIntendant.js
const app = getApp()
import http from "../../utils/http"
import util from "../../utils/util"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    columns: ['每月', '每周'],
    withdrawtype:0,
    show: false,
    weekShow: false,
    monthShow: false,
    weekDay: ['周一','周二','周三','周四','周五','周六','周日'],
    monthDay: [],
    dayName: '请选择',
    day: '',
    safeBottom: `30px`,
  },
  typeShow(){
    this.setData({
      show:true
    })
  },
  dayShow(){
    if(this.data.withdrawtype == 1){
      this.setData({
        weekShow: true
      })
    }else{
      this.setData({
        monthShow: true
      })
    }
  },
  closeWeek(){
    this.setData({
      weekShow: false
    })
  },
  closeMonth(){
    this.setData({
      monthShow: false
    })
  },
  onClose() {
    this.setData({ show: false });
  },
  confirmWeek(event){
    this.setData({
      day:event.detail.index,
      dayName: event.detail.value,
      weekShow: false,
    })
  },
  confirmMonth(event){
    this.setData({
      day:event.detail.index,
      dayName: event.detail.value,
      monthShow: false,
    })
  },
  onConfirm(event) {
    this.setData({
      withdrawtype:event.detail.index,
      show:false,
      day: '',
      dayName: '请选择'
    })
  },
  onCancel() {
    this.setData({
      show:false
    })
  },
  save(){
    let day;
    if(this.data.withdrawtype == 1){
        day  = this.data.day === 6 ? 0 : this.data.day+1
    }else{
      day  = this.data.day+1
    }
    http.post('shop/updateshopinfo',{
      type: 'update',
      day: day,
      withdrawtype: this.data.withdrawtype
    }).then(res => {
      util.toast(res.msg)
    })
  },
  getInfo(){
    http.post('shop/updateshopinfo').then(res => {
      if(res.data.withdrawtype == 1){
        this.setData({
          withdrawtype:res.data.withdrawtype,
          day: res.data.day === 0 ? 6 : res.data.day-1,
          dayName: res.data.day === 0 ? '周日' :this.data.weekDay[res.data.day-1]
        })
      }else{
        this.setData({
          withdrawtype:res.data.withdrawtype,
          day: res.data.day,
          dayName: this.data.monthDay[res.data.day-1]
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const high = app.globalData.safeBottom
    let arr = [];
    for(let i=1; i < 29; i++){
      arr.push(i+'号')
    }
    this.setData({
      safeBottom: `${high}px`,
      monthDay: arr
    })
    this.getInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})